import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 动态路由模块化封装调用
import departmentsRoute from './modules/departments'
import settingsRoute from './modules/settings'
import employeesRoute from './modules/employees'
import permissionsRoute from './modules/permissions'
import salarysRoute from './modules/salarys'
import social_securitysRoute from './modules/social_securitys'
import attendancesRoute from './modules/attendances'
import approvalsRoute from './modules/approvals'

// 动态路由
export const asyncRoutes = [
  departmentsRoute, // 组织架构
  settingsRoute, // 公司设置
  employeesRoute, // 员工管理
  permissionsRoute, // 权限管理
  salarysRoute, // 工资绩效
  social_securitysRoute, // 社保记录
  attendancesRoute, // 考勤管理
  approvalsRoute // 行政审批

]

// 静态路由
export const constantRoutes = [
  { path: '/import', // 表格导入路由
    component: Layout,
    hidden: true, // 不显示到左侧菜单
    children: [{
      path: '',
      component: () => import('@/views/import')
    }]
  },

  { path: '/login', // 登录页
    component: () => import('@/views/login/index'),
    hidden: true
  },
  { path: '/404', // 404页面
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '/', // 主页面
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 将数组合并  , ...asyncRoutes
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
